package yawning.mew.bear;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class SurvivalInstinctsAction extends SimulationEventAction {
	BearThreatSimulator mState;
	double mCooldownExpireTime;

	SurvivalInstinctsAction(BearThreatSimulator state) {
		super(state.mSimEngine);
		mState = state;

		if (mState.mModel.mToon.getTalent(BearModel.SURVIVALINSTINCTS) == 0) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;
		if (mState.mIsLogging) mState.mLog.log("Survival Instincts\n");

		mState.mModel.multiplyIncPhysicalDamage(mState.mModel.multSurvivalInstinctsDR);
		mState.mModel.multiplyIncMagicDamage(mState.mModel.multSurvivalInstinctsDR);

		schedule(mState.mModel.survivalInstinctsBuffDuration);

		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.survivalInstinctsCDDuration;

		return 0.0;
	}

	@Override
	public void onExpire() {
		mState.mModel.multiplyIncPhysicalDamage(1.0f / mState.mModel.multSurvivalInstinctsDR);
		mState.mModel.multiplyIncMagicDamage(1.0f / mState.mModel.multSurvivalInstinctsDR);

		if (mState.mIsLogging) mState.mLog.log("Survival Instincts Expiration\n");
	}
}